home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
GRAPH_FO
/
(GRAPH
/
GRAPH_SO
/
GRVERTEX.C
< prev
Wrap
Text File
|
1991-04-03
|
4KB
|
155 lines
/******************************************************************************
GrVertex.c
Graph methods in Object C.
This implements the GrVertex.
SUPERCLASS = GrNode
Copyright ⌐ 1991 Maarten Meijer. All rights reserved.
CIS 100016,1764; FidoNet 2:512/114
*******************************************************************************/
long gBlokNumber = 1L;
#define kLeftSize 20 /* offsets from center */
#define kRightSize 20
#define kTopSize 10
#define kBottomSize 10
#define FRAMESHAPE FrameRect
#define ERASESHAPE EraseRect
#define HILITESHAPE InvertRect
#include "GrVertex.h"
/* GrVertex methods ********************************************************/
/******************************************************************************
IGraphNode
initialize a vertex
*******************************************************************************/
void
GrVertex::IGraphNode() { /* OVERRIDE */
inherited::IGraphNode();
center.h = center.v = 0;
blokno = gBlokNumber++;
}
/******************************************************************************
_Draw
Draws the vertex outline, used in Draw and SetRegion
*******************************************************************************/
void
GrVertex::_Draw() {
Rect theRect;
GetRect(&theRect);
FRAMESHAPE(&theRect);
}
/******************************************************************************
Draw
Erase and redraw the vertex
*******************************************************************************/
void
GrVertex::Draw() {
Rect theRect;
Str255 number;
short width, height;
FontInfo info;
GetRect(&theRect);
ERASESHAPE(&theRect);
_Draw();
NumToString(blokno, number);
width = StringWidth(number);
GetFontInfo(&info);
height = info.ascent;
MoveTo(center.h - (width>>1), center.v - (height >> 1) + height );
DrawString(number);
if(selected) { /* this can be modified */
GetRect(&theRect); /* this is doubled from _Draw */
InsetRect(&theRect, 1, 1);
HILITESHAPE(&theRect);
}
}
/******************************************************************************
SetRegion
Set the hot region of the vertex.
*******************************************************************************/
void
GrVertex::SetRegion() {
Rect theRect;
inherited::SetRegion();
OpenRgn();
_Draw();
CloseRgn(hotRegion);
}
/******************************************************************************
SetCenter
Set the center of the vertex and redraw it
*******************************************************************************/
void
GrVertex::SetCenter(Point thePoint) {
center = thePoint;
Draw();
SetRegion();
}
/******************************************************************************
GetCenter
return the center of the vertex.
*******************************************************************************/
Point
GrVertex::GetCenter(void) {
return (center);
}
/******************************************************************************
GetRect
Return the rect that encloses the Vertex. This is the ONLY method
that defines the enclosing rect.
*******************************************************************************/
void
GrVertex::GetRect(Rect *r) {
Rect area;
area.top = center.v - kTopSize;
area.left = center.h - kLeftSize;
area.bottom = center.v + kBottomSize;
area.right = center.h + kRightSize;
*r = area;
}
/******************************************************************************
NodeInRect
return true if the Vertex needs to be redrawn if the rect
is changed.
*******************************************************************************/
Boolean
GrVertex::NodeInRect(Rect *r) {
Rect area = *r;
area.top -= kTopSize;
area.left -= kLeftSize;
area.right += kRightSize;
area.bottom += kBottomSize;
return PtInRect(center, &area);
}